package com.cms.recursoshumanos.component.dialog;

import java.util.Calendar;
import java.util.Date;

import com.example.frontendrecursoshumanos.R;
import com.cms.recursoshumanos.utilities.Tool;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TimePicker;

public class CustomTimePickerDialog extends Dialog
{

    private TimePicker mSpinner;
    private Date hora_inic;

    public interface TimeDialogListener 
  	{
        public void ready(Date hora_selec);
        public void cancelled();
    }

    private TimeDialogListener mReadyListener;

    public CustomTimePickerDialog(Context context, Date hora_inic, String title, TimeDialogListener readyListener) 
    {
        super(context);
        this.setTitle(title);
        mReadyListener = readyListener;
        this.hora_inic = hora_inic;

    }

    
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.elementos_spinner_tiempo_picker);
        mSpinner = (TimePicker) findViewById (R.id.tpHora);
       // ArrayAdapter<String> adapter = new ArrayAdapter<String> (mContext, android.R.layout.simple_spinner_dropdown_item, mList);
        //mSpinner.setAdapter(adapter);
        Calendar cal = Calendar.getInstance();
        cal.setTime(hora_inic);
        mSpinner.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY));
        mSpinner.setCurrentMinute(cal.get(Calendar.MINUTE));
        
        Button buttonOK = (Button) findViewById(R.id.dialogOK);
        Button buttonCancel = (Button) findViewById(R.id.dialogCancel);
        buttonOK.setOnClickListener(new android.view.View.OnClickListener()
        {
            public void onClick(View v) 
            {
                int hora = mSpinner.getCurrentHour();
                int min = mSpinner.getCurrentMinute();
                
                
                
                mReadyListener.ready(Tool.getInstance().getHourFormato(hora, min));
                CustomTimePickerDialog.this.dismiss();
            }
        });
        buttonCancel.setOnClickListener(new android.view.View.OnClickListener(){
            public void onClick(View v) 
            {
                mReadyListener.cancelled();
                CustomTimePickerDialog.this.dismiss();
            }
        });
    }
    
  
}